home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16418 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: crchh327.rich.bnr.ca!jobell
  2. From: jobell@bnr.ca (Bret Bieghler)
  3. Newsgroups: comp.lang.c++
  4. Subject: Creating an object via new with ONLY a pointer to the object
  5. Date: 10 Apr 1996 18:55:59 GMT
  6. Organization: Bell-Northern Research Ltd.
  7. Message-ID: <4kh07v$lno@crchh327.rich.bnr.ca>
  8. NNTP-Posting-Host: crchhd4a.rich.bnr.ca
  9.  
  10. An interesting problem I've come across... I was wondering if this
  11. is possible:
  12.  
  13. I have a generic CommandObject which defines several pure virtual
  14. functions.  Derived from CommandObject are user commands, such
  15. as ExitCommand, StatusCommand, etc.
  16.  
  17. To process a command (currently) I do the following:
  18.  
  19.     CommandObject* basePtr;
  20.  
  21.     if (command == "exit")
  22.     {
  23.         basePtr = new ExitCommand;
  24.         basePtr->implement();
  25.     }
  26.     else if (command == "status")
  27.     {
  28.         basePtr = new StatusCommand;
  29.         basePtr->implement();
  30.     }
  31.  
  32. What I would LIKE to do is the the following:
  33.  
  34.     CommandObject* basePtr =  new commandTable[command];
  35.  
  36. where commandTable is an associative array as follows:
  37.  
  38.     Key        Value
  39.     "exit"    ExitCommand*
  40.     "status"    StatusCommand*
  41.  
  42. The problem is if there is a way to create a new object
  43. of a given type having only a pointer to that type.
  44.  
  45. Is this possible?
  46.  
  47. Regards,
  48.  
  49. Joe
  50. -- 
  51. Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
  52. Northern Telecom / Bell-Northern Research
  53. "What?  Evacuate now, in our moment of triumph?  Surely you overestimate their chances."
  54.